module.exports = (mod, beforeRouteEnter)->
    func = mod.beforeRouteEnter
    mod.beforeRouteEnter = (to, from, next)->
        _next = (args)=>
            if args == false
                next(false)
                return
            if func
                await func.call(
                    @
                    to
                    from
                    (args2)=>
                        if args2 == false
                            next(false)
                            return
                        next(
                            (vm)=>
                                args?.call(vm,vm)
                                args2?.call(vm,vm)
                        )
                )
            else
                next((vm)=>args?.call(vm,vm))
        try
            await beforeRouteEnter.call(@, to, from, _next)
        catch err
            if err?.status == 401
                return
            throw err
